package com.kning.mastermind;

import java.util.HashSet;
import java.util.Objects;

/**
 * Element4b - 四位元素对象
 *
 * @author ning
 **/
public class Element4b {
    private int number;
//    private String numberString;
    // 个位值
    private int b1;
    // 十位值
    private int b2;
    // 百位值
    private int b3;
    // 千位值
    private int b4;
    // 所有位的集合
    private HashSet<Integer> bitSet = new HashSet<>(1 << 2);

    /**
     * 构造
     *
     * @param number number
     */
    public Element4b(int number) {
        if (0 > number || 9999 < number) {
            throw new RuntimeException("非法构造：" + number);
        }
        this.number = number;
//        this.numberString = String.valueOf(number);
        this.b1 = number % 10;
        this.b2 = number / 10 % 10;
        this.b3 = number / 100 % 10;
        this.b4 = number / 1000;

        bitSet.add(b1);
        bitSet.add(b2);
        bitSet.add(b3);
        bitSet.add(b4);
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
    }

//    public String getNumberString() {
//        return numberString;
//    }
//
//    public void setNumberString(String numberString) {
//        this.numberString = numberString;
//    }

    public int getB1() {
        return b1;
    }

    public void setB1(int b1) {
        this.b1 = b1;
    }

    public int getB2() {
        return b2;
    }

    public void setB2(int b2) {
        this.b2 = b2;
    }

    public int getB3() {
        return b3;
    }

    public void setB3(int b3) {
        this.b3 = b3;
    }

    public int getB4() {
        return b4;
    }

    public void setB4(int b4) {
        this.b4 = b4;
    }

    public HashSet<Integer> getBitSet() {
        return bitSet;
    }

    public void setBitSet(HashSet<Integer> bitSet) {
        this.bitSet = bitSet;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Element4b element4b = (Element4b) o;
        return number == element4b.number;
    }

    @Override
    public int hashCode() {
        return Objects.hash(number);
    }

    @Override
    public String toString() {
        return "Element4b{" +
                "number=" + number +
                '}';
    }
}
